package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import com.example.demo.util.Result;
import com.example.demo.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/userList")
    public Result userList(@RequestBody(required = false) User user){
        return ResultUtil.success(userService.userList(user));
    }

    @PostMapping("/add")
    public Result addUser(@RequestBody User user){
        return ResultUtil.whether(userService.addUser(user));
    }

    @PostMapping("/update")
    public Result updateUser(@RequestBody User user){
        return ResultUtil.whether(userService.updateUser(user));
    }

    @DeleteMapping("/delete")
    public Result delete(@RequestParam("id") String id){
        return ResultUtil.whether(userService.delete(id));
    }

}
